package name.huzhenbo.java.patterns.singleton;

/**
 * safe but incurs the cost of synchronization on every invocation.
 */
class SynchronizedLazySingleton {
    private static SynchronizedLazySingleton instance;
    private int creationCount = 0;

    private SynchronizedLazySingleton() {
        creationCount++;
    }

    public static synchronized SynchronizedLazySingleton getInstance() {
        if (instance == null) {
            instance = new SynchronizedLazySingleton();
        }
        return instance;
    }

    public int getCreationCount() {
        return creationCount;
    }
}
